<template>
	<div class="chushoubox">
		<div id="kong">
			<img class="kong-img" src="../../img-shopping/pic@2x.png"/>
			<p class="kong-p">这里没有任何商品呢</p>
			<div @click="zhuye()" class="kong-b"><span class="kong-btn">去首页</span></div>
		</div>
		<ul class="shoplist-list">
			<li class="shoplist-item" v-for="(item,index) in orderlist">
				<div class="shoplist-item-con">
					<img :src="'http://www.ntyouxuan.com/'+item.default_image"/>
					<div class="shoplist-item-text">
						<h3 v-text="item.goods_name">良万家海鲜花蛤即食罐头即食罐头海鲜花 蛤即食罐头良万家良万家...</h3>
						<ul class="shoplist-item-jiage">
							<li><span>零售价</span><span v-text="'￥'+item.price">￥26.90</span></li>
							<li><span>佣<i></i>金</span><span v-text="'￥'+item.commission">￥26.90</span></li>
							<li><span>库<i></i>存</span><span v-text="item.stock">9999</span></li>
							<li><span>销<i></i>量</span><span v-text="item.sales">100</span></li>
						</ul>
					</div>
					<router-link :to="{name:'shopXQ',params:{id:item.goods_id}}"></router-link>
				</div>
				<div class="shoplist-item-btn"><span @click="deleteshop(item.goods_id,index)">删除</span><span v-if="item.if_show==1" @click="shangxiajia(item.goods_id,index,false)">下架</span><span v-else @click="shangxiajia(item.goods_id,index,true)">上架</span><span @click="shoparea(item.goods_id)">编辑</span></div>
			</li>
		</ul>
		<deletctr :msg="deletemsg" @btnstatus="deletebtn" v-show="deleteshow"></deletctr>
	</div>
</template>

<script>
	import deletctr from "@/components/widget/deletectrol"
	export default{
		name:"chushou",
		data () {
			return{
				user:0,
				pagenum:1,
				orderpage:1,
				scrollstatu:true,
				orderlist:[],
				deletemsg:'你确定要<span>删除</span>该商品吗？',
				deleteshow:false,
				shopctrid:'',
				shoplistind:'',
				btns:''
			}
		},
		components:{deletctr},
		created:function(){
			this.user=localStorage.getItem("nt_user");
		},
		methods:{
			chushouajax:function(){
				var self=this;
				$.ajax({
					type:"get",
					url:furl+"index.php?app=ajax_seller_member&act=my_goods",
					data:{"token":self.user,"type":"3","page":self.orderpage},
					dataType:"json",
					success:function(res){
						if(res.retval.goods_list){
							self.orderlist=self.orderlist.concat(res.retval.goods_list);
						}
						self.pagenum=res.retval.page.page_count;
						self.scrollstatu=true;
						self.panum=res.retval.page.item_count;
						if (self.panum != 0) {
							$('#kong').css("display","none");
						}
					}
				});
			},
			shoparea:function(id){
				this.$router.push({path:'/business/shoparea',query:{'spid':id}});
			},
			zhuye: function() {
				window.location.href = 'http://www.ntyouxuan.com/newnt/#/';
			},
			scrollajax:function(){
				if(this.scrollstatu){
					if(this.orderpage+1<=this.pagenum){
						var dSH=$(document).scrollTop()
						var dH=$(document).height()
						var wH=$(window).height()
						if((dSH+wH)/dH>0.8){
							this.scrollstatu=false;
							this.orderpage=this.orderpage+1;
							this.chushouajax();
						}
					}
					
				}
			},
			deletebtn:function(data){
				if(this.btns==1){
					if(data){
						console.log(this.shopctrid,this.shoplistind);
						var self=this;
						$.ajax({
							type:"post",
							url:furl+"index.php?app=ajax_seller_member&act=drop_goods",
							data:{'token':self.user,'goods_id':self.shopctrid},
							dataType:'json',
							success:function(res){
								if(res.done){
									self.orderlist.splice(self.shoplistind,1);
									self.deleteshow=false;
								}
							}
						});
					}else{
						this.deleteshow=false;
					}
				}
				if(this.btns==2){
					if(data){
						console.log(this.shopctrid,this.shoplistind);
						var self=this;
						$.ajax({
							type:"post",
							url:furl+"index.php?app=ajax_seller_member&act=ajax_col_if_show",
							data:{'token':self.user,'goods_id':self.shopctrid},
							dataType:'json',
							success:function(res){
								if(res.done){
									self.orderlist.splice(self.shoplistind,1);
									self.deleteshow=false;
								}
							}
						});
					}else{
						this.deleteshow=false;
					}
				}
			},
			deleteshop:function(id,ind){
				this.shopctrid=id;
				this.btns=1;
				this.deletemsg='你确定要<span>删除</span>该商品吗？';
				this.shoplistind=ind;
				this.deleteshow=true;
			},
			shangxiajia:function(id,ind,stu){
				this.shopctrid=id;
				this.btns=2;
				if(stu){
					this.deletemsg='你确定要<span>上架</span>该商品吗？';
				}else{
					this.deletemsg='你确定要<span>下架</span>该商品吗？';
				}
				this.shoplistind=ind;
				this.deleteshow=true;
			}
		},
		mounted:function(){
			this.chushouajax();
			var self=this;
			window.addEventListener("scroll",self.scrollajax);
		},
		destroyed:function () {
		    this.scrollstatu = false;
		}
	}
</script>

<style>
	#kong{
		text-align: center;
		margin: 0 auto;
		margin-top: 2.2rem;
	}
	#kong img{
		width: 3.6rem;
		height: 3.2rem;
	}
	#kong .kong-p{
		font-size: 0.32rem;
		color: #999999;
		margin-top: 0.84rem;
	}
	#kong .kong-b{
		width: 1.8rem;
		height: 0.7rem;
		border:1px solid #fb9722;
		margin-left:2.85rem;
		margin-top: 0.44rem;
		border-radius: 0.35rem;
	}
	#kong .kong-btn{
		font-size: 0.33rem;
		color: #fb9722;
		line-height: 0.7rem;
	}
</style>